<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有!                                |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: Joey<shaoshuai@clcw.com.cn>                                     |
// +------------------------------------------------------------------------+
//
namespace AuctionCore\Cash;

class Cash{
    
    public function getCashList($page, $pageSize, $params)
    {
        
        $where = [];
        if(isset($params['status'])){
            $where['c.status'] = $params['status'];
        }
        
        if($params['userId']){
            $where['u.user_id'] = $params['userId'];
        }
        if($params['mobile']){
            $where['u.mobile'] = $params['mobile'];
        }
        if($params['realName']){
            $where['u.real_name'] = $params['realName'];
        }
        if($params['icard']){
            $where['u.icard'] = $params['icard'];
        }
        if($params['startTime'] && $params['endTime']){
            $where['c.create_time'] = ['between', [$params['startTime'], $params['endTime']]];
        }elseif($params['endTime']){
            $where['c.create_time'] = ['lt' , $params['endTime']];
        }elseif($params['startTime']){
            $where['c.create_time'] = ['gt' , $params['startTime']];
        }
        
        $list = M('user_cash', 'clcw_', 'DB_CLCW')->alias('c')->join('left join clcw_user u ON c.user_id=u.user_id')
        ->field('c.id,c.user_id,u.mobile,u.real_name,u.icard,c.amount,c.status,c.card,c.bank,c.status,c.remark,c.create_time,c.withdraw_time')
        ->where($where)->page($page, $pageSize)->select();
        
        $total = M('user_cash', 'clcw_', 'DB_CLCW')->alias('c')->join('left join clcw_user u ON c.user_id=u.user_id')
        ->where($where)->count();
        
        $amount = M('user_cash', 'clcw_', 'DB_CLCW')->field('SUM(c.amount) amount')->alias('c')->join('left join clcw_user u ON c.user_id=u.user_id')
        ->where($where)->find();
        
        return ['list' => $list, 'total' => $total, 'amount' => $amount['amount']];
        
    }
    
}